import json5,json

import config


def read_json_file_to_map(file_path):
    """读取JSON文件并将其转换为Python字典"""
    with open(file_path, 'r', encoding='utf-8') as file:
        data = json.load(file)
    return data



def read_json5_file(file_path: str) -> dict:
    """读取 JSON5 文件并转换为 Python 字典"""
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            data = json5.load(file)  # 将 JSON5 解析为字典
            return data
    except FileNotFoundError:
        print(f"错误：文件 '{file_path}' 不存在")
        return {}
    except json5.JSON5DecodeError as e:
        print(f"JSON5 解析错误：{e}")
        return {}
    except Exception as e:
        print(f"其他错误：{e}")
        return {}


# 使用示例
if __name__ == "__main__":
    print(config.CONFIG.get('dev')['mysql']['host'])